package com.dayu.web.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dayu.web.pojo.User;
import com.dayu.web.vo.RESTResponse;

/**
 * 用户类
 * 
 * @author Chenjiawei
 *
 *         2017年5月24日
 */
@Controller
@RequestMapping("/unitalk/v1.0")
public class UserCtrl {

	static Logger LOGGER = LoggerFactory.getLogger(UserCtrl.class);

	/**
	 * 登陆接口
	 * 
	 * @param user
	 *            用户名，密码
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/auth.json", method = { RequestMethod.POST })
	public String login(@RequestBody User user) {

		LOGGER.info("name:" + user.getName() + "  " + "pwd:" + user.getPwd());

		if ("admin".equals(user.getName()) & "123456".equals(user.getPwd())) {

			Map<String, String> map = new HashMap<String, String>();
			map.put("Token", UUID.randomUUID().toString());

			return RESTResponse.of(map).toString();

		} else {

			return RESTResponse.of(1, "登陆失败！").toString();
		}
	}
}
